import React, { Component } from 'react'
import { View, Text } from '@tarojs/components'
import Taro from '@tarojs/taro'
import Navbbar from '../../components/Navbbar'
import Searchcard from '../../components/Searchcard'
import tools from '../../utils/tools'
import './index.less'
export default class Collect extends Component {
  state = {
    collectList:[],
  }

  componentDidMount(){
   this.getList()
  
  }
  componentDidShow () {
    this.getList()
  }
  getList = ()=>{
    Taro.request({
      url: 'http://127.0.0.1:3007/api/showlist',
      method: 'GET',
      success:(res)=> {
        this.setState({
          collectList:res.data.data || tools.tGet('collectList')||[]
        })
      }
    })
  }
  handleGoto = (id)=>{
    Taro.navigateTo({
      url:`../detail/index?id=${id}`
    })
  }
  handleDelete = (id)=>{
    Taro.request({
      url: 'http://127.0.0.1:3007/api/delete',
      method: 'POST',
      data:{id},
      success:(res)=> {
        this.getList()
       console.log(res)
      }
    })
  
  }
  render() {
    return (
      <View className='collect'>
        <Navbbar type={5} >收藏</Navbbar>
        <View className='collect_box'>
        {
          this.state.collectList&& this.state.collectList.map(item=><Searchcard gotoDetail={this.handleGoto} handleDelete={this.handleDelete} type='s1' key={item.id} pic={item.pic} id={item.id} name={item.name} tag={item.tag} cookingtime={item.cookingtime} islike='1' ></Searchcard>)
        }
      </View>
      </View>
    )
  }
}
